<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">客户名称</div>
                <div class="field">
                    <input name="cstNm" ligerui="width:150" id="cstNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">客户类型</div>
                <div class="field">
                    <select name="cstTypCd" id="cstTypCd" ligerui="width:150">
                        <option value=" " seleted>请选择</option>
                       <c:forEach items="${searchSelectCsttypcdlist }" var="csttypcd">
                        	<option value="${csttypcd.key }">${csttypcd.value }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
       <%--      <div class="fieldBox">
                <div class="label">客户属性</div>
                <div class="field">
                    <select name="cstRlTyp" id="cstRlTyp">
                       <option value=" ">请选择</option>
                       <c:forEach items="${cstRlTypCdList }" var="cstRlcd">
                       		<c:if test="${currentCstRlType == cstRlcd.key }">
                       			<option value="${cstRlcd.key }" selected>${cstRlcd.value }</option>
                       		</c:if>
                        	<c:if test="${currentCstRlType != cstRlcd.key }">
                       			<option value="${cstRlcd.key }">${cstRlcd.value }</option>
                       		</c:if>
                       </c:forEach>
                    </select>
                </div>
            </div> --%>
            <div class="fieldBox">
                <div class="label">所属机构</div>
                <div class="field">
                    <select name="buOrgCd" id="buOrgCd" ligerui="width:150">
                        <option value=" " seleted>请选择</option>
                        <c:forEach items="${orgListList }" var="org">
                        	<c:if test="${currentBuOrgCd == org.key }">
                        		<option value="${org.key }" selected>${org.value }</option>
                        	</c:if>
                        	<c:if test="${currentBuOrgCd != org.key }">
                        		<option value="${org.key }">${org.value }</option>
                        	</c:if>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" class="sq-button sq-button-round">清空</span>
            </div>
            
            <!-- hide data -->
		    <div class="fieldBox col_100" style="display:none;">
		       <div class="field">
		          <input name="multiRowName" id="multiRowId" type="text" class="ui-textbox" value="${multiRow}">
		       </div>
		    </div>
        </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	var cstRlFlag = '${cstRlFlag}';
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();
	    clearBtnEvent();
	});
	
	
	//清空按钮事件
	function clearBtnEvent(){
		 $("#clearBtn").click(function(event) {
		        $("#resetBtn").click();  //重置 input-text
		        var form = liger.get("searchBar");
		        form.setData({  //重置select等特殊表单
		            "cstTypCd":" ",
		          //  "cstRlTyp":" ",
		            "buOrgCd":" "
		        });
		 });
	}
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		 $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         data["crtTm"] = $("#crtTm").val();
	         //alert(JSON.stringify(data));
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/customer/cstbscinfo/initList.do',
	    	method : 'get',
	    	parms:getSearchParams(),
	        columns: [
	       /*      { display: '客户性质', name: 'cstStsCdNm', minWidth: 60, enabledSort:true },
	            { display: '客户级别', name: 'cstLvlCdNm', minWidth: 60 , enabledSort:true}, */
	            { display: '客户名称', name: 'cstNm', minWidth: 100 , enabledSort:true
	            	/* ,render: function (rowdata, rowindex, value, column) { 
	            		if(StringUtils.isEmpty(value)){
	                		value = "";
	                	}
	            		var h = '';
	            		    h='<a href="javascript:showDetail(';
	                        h+="'"+171023030000533+"'";
	                        h+=",'"+1+"'";
	                        h+=')">'+value+'</a>'
	                        return h;
	            		} */
	            
	            },
	            { display: '客户类型', name: 'cstTypCdNm', width: 60 , enabledSort:true},
	            { display: '证件/组织机构代码', name: 'certNo', minWidth: 200 , enabledSort:true},
	            {
	                display: '操作',
	                isSort: false,
	                width: 100,
	                render: function (rowdata, rowindex, value){
	                    return "";
	                }
	            }
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    
	    var multiRow = $("#multiRowId").val();
	    if(StringUtils.isEmpty(multiRow)){
	    	 grid.options.isSingleCheck=false;
	    }else if(multiRow == "false"){
	    	grid.options.isSingleCheck=true;
	    }else if(multiRow == "true"){
	    	grid.options.isSingleCheck=false;
	    }
	}
	
	//查看数据
	function showDetail(_id,_cstTypCd){
		//1 自然人  2 法人
		if(_cstTypCd == 1){
			parent.mainApp.f_addTab('tab_customer_np_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpDetailPage.do?id='+_id);
		}else if(_cstTypCd == 2){
			parent.mainApp.f_addTab('tab_customer_corp_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/toCustCstBacInfoCorpDetailPage.do?id='+_id);
		}
	}
	
	//返回给调用窗口,返回结果为Map集合
	frameElement.dialog.onOk = function(){
		var selectedRows = grid.getSelectedRows();
		//判断多选还是单选
		var cstMap = new HashMap();
		if(grid.options.isSingleCheck == true){
			//单选
			if(selectedRows.length != 1){
				UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_ONLY_A_ROW);
				return;
			}
			var _id = selectedRows[0].id;
			var _cstNm = selectedRows[0].cstNm;
			cstMap.put(_id, _cstNm);
		}else{
			//多选
			if(selectedRows.length <=0){
				UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_MORE_ROW);
				return;
			}
			var i = 0;
			for (i = 0; i < selectedRows.length; i++) {
				var _id = selectedRows[i].id;
				var _cstNm = selectedRows[i].cstNm;
				cstMap.put(_id, _cstNm);
			}
		}
		return cstMap;
	}
	
	frameElement.dialog.onCancel = function (){
		frameElement.dialog.close();
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
		
	
	function clearBtn(){
		var form = new liger.get("searchBar");
		form.clear();
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	
</script>
</body>
</html>